#! /usr/bin/python
# -*- coding: cp1250 -*-

import re, string
import pepe.p_txt.bigtxt as bt

"""
import pepe.p_dtm.vlookup as vlkp

x = vlkp.VLookup()
x.fill(  ifile=r'tb-transfer-bridge-2007.dat'
       , kIndex=0, vIndex=4
       , cDelimiter='^')
print x.search(key)
"""

class VLookup:
    """ """
    def __init__(self):
        ''' '''
        pass

    def fill(self, ifile='', kIndex=0, vIndex=0, cDelimiter='^'):
        ''' '''
        self.ifile = ifile
        self.kIndex = kIndex
        self.vIndex = vIndex
        self.cDelimiter = cDelimiter
        self.data = {}

        for line in bt.lines(self.ifile):
            line = re.sub('\n', '', line)
            cols = string.split(line, self.cDelimiter)
            self.data[cols[kIndex]] = cols[vIndex]

    def search(self, key):
        ''' '''
        if self.data.has_key(key):
            return self.data[key]
        else:
            return 'n/a'
